package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.DyConfig;
import com.ruoyi.system.mapper.DyConfigMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DyUserinfoMapper;
import com.ruoyi.system.domain.DyUserinfo;
import com.ruoyi.system.service.IDyUserinfoService;

/**
 * 用户卡信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-04-25
 */
@Service
public class DyUserinfoServiceImpl implements IDyUserinfoService 
{
    @Autowired
    private DyUserinfoMapper dyUserinfoMapper;
    @Autowired
    private DyConfigMapper dyConfigMapper;

    @Override
    public List<String> getAllDomain(){
        return dyUserinfoMapper.getAllDomain();
    }

    @Override
    public void updateLastOnlineOffLine(){
        DyConfig conf = dyConfigMapper.selectDyConfigById(1L);
        Integer seconds = 20;
        if(conf!=null){
            seconds = conf.getTimeout();
        }
        dyUserinfoMapper.updateLastOnlineOffLine(seconds);
    }
    @Override
    public List<DyUserinfo> selectDyUserinfoListByIds(List<Long> ids){
//        System.out.println("========================");
//        System.out.println(ids);
        return dyUserinfoMapper.selectDyUserinfoListByIds(ids);
    }

    //修改为导出状态
    @Override
    public void updateExp(Long id){
        dyUserinfoMapper.updateExp(id);
    }
    @Override
    public List<Map<String, Object>> getStatisCount(int type){
        return dyUserinfoMapper.getStatisCount(type);
    }

    @Override
    public int getCount(int type){
        return dyUserinfoMapper.getCount(type);
    }
    /**
     * 查询用户卡信息
     * 
     * @param id 用户卡信息主键
     * @return 用户卡信息
     */
    @Override
    public DyUserinfo selectDyUserinfoById(Long id)
    {
        return dyUserinfoMapper.selectDyUserinfoById(id);
    }

    @Override
    public DyUserinfo selectDyUserinfoByOrderId(String orderid){
        return dyUserinfoMapper.selectDyUserinfoByOrderId(orderid);
    }
    /**
     * 查询用户卡信息列表
     * 
     * @param dyUserinfo 用户卡信息
     * @return 用户卡信息
     */
    @Override
    public List<DyUserinfo> selectDyUserinfoList(DyUserinfo dyUserinfo)
    {
        return dyUserinfoMapper.selectDyUserinfoList(dyUserinfo);
    }

    /**
     * 新增用户卡信息
     * 
     * @param dyUserinfo 用户卡信息
     * @return 结果
     */
    @Override
    public int insertDyUserinfo(DyUserinfo dyUserinfo)
    {
        dyUserinfo.setCreatTime(DateUtils.getNowDate());
        return dyUserinfoMapper.insertDyUserinfo(dyUserinfo);
    }

    /**
     * 修改用户卡信息
     * 
     * @param dyUserinfo 用户卡信息
     * @return 结果
     */
    @Override
    public int updateDyUserinfo(DyUserinfo dyUserinfo) {
        String status = dyUserinfo.getStatus();
        if(status!=null){
            switch (status){
                case "0":
                    dyUserinfo.setOperationRecord("拒绝验证码错误");
                    dyUserinfo.setWait(0);
                    break;
                case "1":
                    break;
                case "2":
                    dyUserinfo.setWait(0);
                    dyUserinfo.setOperationRecord("放行银行app");
                    break;
                case "3":
                    dyUserinfo.setWait(0);
                    dyUserinfo.setOperationRecord("放行otp");
                    break;
                case "5":
                    dyUserinfo.setWait(0);
                    dyUserinfo.setOperationRecord("放行邮箱验证");
                    break;
                case "7":
                    dyUserinfo.setWait(0);
                    dyUserinfo.setOperationRecord("放行pin");
                    break;
                case "9":
                    dyUserinfo.setWait(0);
                    dyUserinfo.setOperationRecord("放行pin+otp");
                    break;
                case "101":
                    dyUserinfo.setWait(0);
                    dyUserinfo.setOperationRecord("拒绝密码错误");
                    break;
                case "100":
                    dyUserinfo.setWait(0);
                    dyUserinfo.setOperationRecord("拒绝付款失败");
                    break;
                case "200":
                    dyUserinfo.setWait(0);
                    dyUserinfo.setOperationRecord("放行付款成功");
                    break;
                case "400":
                    dyUserinfo.setWait(0);
                    dyUserinfo.setOperationRecord("删除");
                    break;
            }
        }

        dyUserinfo.setUpdateTime(DateUtils.getNowDate());
        return dyUserinfoMapper.updateDyUserinfo(dyUserinfo);
    }

    /**
     * 批量删除用户卡信息
     * 
     * @param ids 需要删除的用户卡信息主键
     * @return 结果
     */
    @Override
    public int deleteDyUserinfoByIds(Long[] ids)
    {
        return dyUserinfoMapper.deleteDyUserinfoByIds(ids);
    }

    @Override
    public int overDyUserinfoByIds(Long[] ids){
        return dyUserinfoMapper.overDyUserinfoByIds(ids);
    }
    /**
     * 删除用户卡信息信息
     * 
     * @param id 用户卡信息主键
     * @return 结果
     */
    @Override
    public int deleteDyUserinfoById(Long id)
    {
        return dyUserinfoMapper.deleteDyUserinfoById(id);
    }
}
